const assessmentObj = this.getApiPage().getApiWidgetByAliasName('演练评估分值')?.widgetObj;
const form = this.getApiPage().retrievePlugin('base-forms');
const prefix = this.pageObj.getVariables().find(v => v.name === "environmentType")?.value;

const requestPost = (url, body) => {
  return fetch(url, {
    method: 'POST',
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(body)
  }).then(res => res.json())
};

console.log('演练评估分值===========', this);
if (assessmentObj) {
  const status = $(this.__box).attr('data-status');
  if (status) {
    // 保存分值
    const datas = assessmentObj.getData();
    const body = datas.map(({ label, rate = 10, content }) => ({
      "content": content,
      "eventId": this.widgetObj._option?.defaultData?.id,
      "quota": label,
      "score": rate,
    }));

    requestPost(`/${prefix}SummaryAssessmentSV/assessmentRecord/batchInsert`, body).then(res => {
      $(this.__box).removeAttr('data-status');
      this.hideWidget();
    });
  } else {
    const $assessModal = document.querySelector('#assess-modal .layui-layer-content');
    // 显示分值编辑面板
    $assessModal.innerHTML = '';
    this.widgetObj?.renderFooter([
      {
        "label": "确定",
        "value": "success"
      }
    ]);
    assessmentObj?.show($assessModal);
    $(this.__box).attr('data-status', 'push');
  }
}


this.widgetObj?.renderContent('演练评估分值');



